package com.tanhua.server.controller;

import com.tanhua.server.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class VideoController {

    @Autowired
    private VideoService videoService;
    /**
     * 小视频-发布小视频
     * POST /smallVideos
     *
     * @param videoThumbnail 视频的封面图
     * @param videoFile      视频文件
     */
    @PostMapping
    public ResponseEntity saveVideo(MultipartFile videoThumbnail,MultipartFile videoFile) throws IOException {
        return videoService.saveVideo(videoThumbnail,videoFile);

    }
    /**
     * 小视频-视频列表
     * GET/smallVideos
     */
    @GetMapping
    public ResponseEntity findVideoList (@RequestParam(defaultValue = "1") int page,
                                         @RequestParam(defaultValue = "10")int pagesize){
        if (page<=0){
            page=1;
        }
        return videoService.findVideoList(page,pagesize);
    }
    /**
     * 小视频-关注
     * POST /smallVideos/:uid/userFocus
     */
    @PostMapping("/{followUserId}/userFocus")
    public  ResponseEntity followUser(@PathVariable("followUserId") Long followUserId){
        return videoService.followUser(followUserId);
    }
    /**
     * 小视频-取消关注
     * POST /smallVideos/:uid/userUnFocus
     */
    @PostMapping("/{followUserId}/userUnFocus")
    public  ResponseEntity disFollowUser (@PathVariable("followUserId") Long followUserId){
        return videoService.disFollowUser(followUserId);
    }
}
